home *** CD-ROM | disk | FTP | other *** search
- // This program is graphics file format shower.
- // We can show you formats :
- // TGA (TARGA)
- // GIF (CompuServe)
- // PCX (Zsoft)
- // BMP (DIB) (Microsoft Windows bitmap)
- // MONO & 16 colors pictures are displaied in standart VGA 16 colors video mode
- // 256 & Gray - in VGA and SVGA 256 colors modes
- //
- // you SVGA must have VESA BIOS extention !!!
- //
- // To display True Color pictures we use color quantization and
- // show them in SVGA 256 colors modes
- //
- // Written by Podvoysky E. & Kiselev J. CZ 1994.
-
- #pragma -ml
-
- #include <conio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <dir.h>
- #include <mem.h>
- #include <dos.h>
-
- #include "graph.h"
- #include "formats.h"
- #include "formconv.h"
- #include "palette.h"
- #include "mapper.h"
- #include "mapper2.h"
- #include "quant.h"
- #include "keymouse.h"
-
- VGApalette pal;
- BGRpalette BGRpal;
-
- graph_file_reader *grf_r;
- image_keeper *keeper = NULL;
-
- void init_keeper(image_type im_type, BOOL force ) {
-
- if (force || (getmaxx()+1 < grf_r -> width) ||
- (getmaxy()+1 < grf_r -> height)) {
-
- if (!EXM_initialized) manager_initialize();
- keeper = new image_keeper(UNKNOWN,
- im_type,
- grf_r -> width,
- grf_r -> height,
- grf_r -> palette,
- grf_r -> top_to_bottom);
- if (keeper == NULL) return;
- if (! keeper -> file_ok) {
- delete keeper;
- keeper = NULL;
- }
- /* if (keeper -> where == DISK) {
- delete keeper;
- keeper = NULL;
- }
- */ }
- }
-
- void show_picture(int x0, int y0) {
- int i, y, width;
- BYTE *tmp;
-
- width = min(keeper->width, getmaxx()+1);
- for (i = getmaxy(), y = y0 + getmaxy(); i >= 0; i--, y--) {
- tmp = keeper->give_line(y);
- putrow( (rowptr) (tmp+x0), 0, i, width);
- }
- }
-
- #define MOUSE_SENSITIVITY 3
- #define KEY_STEP 3
- void scroll_picture() {
- int x0 = 0, y0 = 0, xold = 0, yold = 0;
- int maxx0, maxy0;
- int step;
-
- WORD key;
- int d_mousex, d_mousey;
- BOOL fin = FALSE, shft;
-
- initmouse_easy();
- setmouserange(0,0,getmaxx(),getmaxy());
-
- if (kbhit() && (readkeyword() == kwEsc)) return;
- clearkey();
-
- if (getmaxx() < 350) step = KEY_STEP; else step = 2*KEY_STEP;
- maxx0 = keeper->width-1 - getmaxx();
- maxy0 = keeper->height-1 - getmaxy();
-
- do { // while (!fin)
- setmousepos( getmaxx()/2, getmaxy()/2);
- d_mousex = d_mousey = 0;
-
- while ((!kbhit()) && (d_mousex == 0) && (d_mousey == 0)) {
- d_mousex = (mousex - getmaxx()/2)/MOUSE_SENSITIVITY;
- d_mousey = (mousey - getmaxy()/2)/MOUSE_SENSITIVITY;
- }
-
-
- if (kbhit()) {
- key = readkeyword();
- shft = keyboardstatus() & 3; // was shift pressed?
-
- switch (key) { // when shift key is unimportant
- case kwHome:
- case kwShiftHome: x0 = 0; break;
-
- case kwEnd:
- case kwShiftEnd: x0 = maxx0; break;
-
- case kwPgUp:
- case kwShiftPgUp: y0 -= getmaxy()/2; break;
-
-
- case kwPgDn:
- case kwShiftPgDn: y0 += getmaxy()/2; break;
- }
-
- if (shft) switch (key) {
- case kwLeft:
- case kwShiftLeft: x0 -= getmaxx()/2; break; // NumLock may cause kwShiftLeft
-
- case kwRight:
- case kwShiftRight: x0 += getmaxx()/2; break;
-
- case kwUp:
- case kwShiftUp: y0 -= 5*step; break;
-
- case kwDown:
- case kwShiftDown: y0 += 5*step; break;
- }
- else switch (key) {
- case kwLeft:
- case kwShiftLeft: x0 -= step; break; // NumLock may cause kwShiftLeft
-
- case kwRight:
- case kwShiftRight: x0 += step; break;
-
- case kwUp:
- case kwShiftUp: y0 -= step; break;
-
- case kwDown:
- case kwShiftDown: y0 += step; break;
-
- }
-
- switch (key) {
- case kwEsc:
- case kwAltX:
- case kwF4:
- case kwF10:
- case kwEnter:
- case kwSpace:
- case kwCtrlBreak: fin = TRUE;
- }
- }
- else { // not kbhit, mouse moved
- x0 += d_mousex*step;
- y0 += d_mousey*step;
- }
-
- if (!fin) {
- x0 = min(x0, maxx0);
- y0 = min(y0, maxy0);
- x0 = max(x0, 0);
- y0 = max(y0, 0);
-
- if ((xold - x0) || (yold - y0)) show_picture(x0,y0);
- xold = x0; yold = y0;
- }
- }
- while (!fin);
-
- }
-
- void main(int argc, char *argv[]) {
- int i,j;
- int inc_line,currline, cols;
- BYTE *dest, *tmp , *dest2;
- // color_selector *selector;
- // color_mapper *mapper;
- color_reductor *reductor = NULL;
-
- if(argc < 2) {
- printf("usage : shower graphfile \n");
- printf("for example :\n");
- printf(" SHOWER WORLD.TGA \n");
- printf(" supported formats: TGA,GIF,PCX,BMP (DIB) \n");
- exit(0);
- }
-
- minheap = 110000L;
- grf_r = open_image_file(argv[1]);
- if (grf_r==NULL) {printf("%s\n",format_file_error_report()); exit(0);}
-
- if(grf_r->top_to_bottom) {currline = 0;inc_line = 1;}
- else {currline = grf_r->height-1;inc_line =-1;}
-
- dest = new BYTE [grf_r->width+1];
-
- if (graphinit() < 0) {printf("error graphics initializing."); exit(0);}
-
- switch(grf_r->source_type) {
- case MONOIMG:
- for(i=grf_r->height-1;i>=0;i--) {
- grf_r->get_next_line();
- if(grf_r->source_ext_type == MONOGIF) {
- for(j=0;j<grf_r->width;j++) {
- if(grf_r->source_line[j] != 0) dest[j] = WHITE;
- else dest[j] = BLACK;
- }
- }
- else mono2row(grf_r->source_line,dest,WHITE,grf_r->width);
- // black & white
- putrow((rowptr)dest,0,currline,grf_r->width);
- currline += inc_line;
- if(kbhit() && (readkeyword() == kwEsc)) goto finish;
- goto finish;
- }
- break;
- case COLOR16IMG:
- switchmode(VGA16);
- /*
- if(grf_r->height > 480 || grf_r->width > 640)
- switchmode(SVGA800x600x16);
- */
- init_keeper(COLOR16IMG, FALSE);
-
- for(i=0;i<16;i++) {
- pal[i].r = grf_r->palette[i].r/4;
- pal[i].g = grf_r->palette[i].g/4;
- pal[i].b = grf_r->palette[i].b/4;
- }
- setVGApalette(pal);
- for(i = grf_r->height; i > 0 ; i--) {
- grf_r->get_next_line();
- if(grf_r->source_ext_type != COLOR16_1PIXEL) {
- if(grf_r->source_ext_type == COLOR16_2PIXEL)
- col16A2col16B(grf_r->source_line,dest,grf_r->width);
- else col16plane2col16B(grf_r->source_line,dest,grf_r->width);
- // 16 colors
- tmp = dest;
- putrow((rowptr)dest,0,currline,grf_r ->width);
- }
- else tmp = grf_r->source_line;
-
- putrow((rowptr) tmp, 0,currline,grf_r ->width);
- currline += inc_line;
-
- if (keeper) keeper -> store_line(tmp);
- if(kbhit() && (readkeyword() == kwEsc)) goto finish;
-
- }
- break;
- case GRAY256IMG:
- case COLOR256IMG:
- choosevideomode(grf_r);
- // switchmode(VGA256);
- init_keeper(COLOR256IMG, FALSE);
-
-
- setpalette_by_BGR(grf_r->palette);
- for(i = grf_r->height; i > 0; i--) {
- grf_r->get_next_line();
- // 256 colors
- putrow((rowptr)grf_r->source_line,0,currline,grf_r->width);
- currline += inc_line;
-
- if (keeper) keeper -> store_line(grf_r->source_line);
- if(kbhit() && (readkeyword() == kwEsc)) goto finish;
- }
- break;
-
- case TRUECOLORIMG:
-
- choosevideomode(grf_r);
- // switchmode(VGA256);
- if (!EXM_initialized) manager_initialize();
-
- stand_palette(pal);
-
- init_keeper(COLOR256IMG, FALSE);
- reductor = new color_reductor (grf_r, TRUE, 255);
-
- if (!reductor->initialized) {
- printf("\a\a Not enough memory!");
- goto finish;
- }
-
-
- if (reductor-> pass1() < 0 ) break;
- setpalette_by_BGR(reductor->my_colormap);
-
- for( i = 0; i < grf_r->height; i++) {
- reductor->process_line(currline,dest);
- putrow((rowptr)dest,0,currline,grf_r-> width);
- currline += inc_line;
- if (keeper) keeper -> store_line(dest);
-
- if(kbhit() && (readkeyword() == kwEsc)) {
- goto finish;
- }
- }
- delete reductor;
- break;
-
-
- }
-
- if (keeper) scroll_picture();
- else delay_key1(120000);
-
- finish: if (keeper) delete keeper;
- if (EXM_initialized) manager_finish(TRUE);
-
- delete dest;
- delete grf_r;
- closegraph();
- printf("Image shower. By ^Z 1994.\n");
- }
-
-